
public class Solution {
    public static class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode ReverseList(ListNode head) {
        ListNode pre = null;
        ListNode next;
        while(head!=null){
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }
    public static void main(String args[]){
         Solution S = new Solution();
         ListNode head =new  ListNode(-1);
        ListNode head_ = head;
        for(int i=0; i<5;i++){
            head.next = new ListNode(i);
            head = head.next;
        }
        S.ReverseList(head_);


    }
}